<template>
  <div style="display:flex">
    <div class="talk_con">
      <!-- 信息展示板块 talk_show -->
      <div class="talk_show" id="words"></div>
      <!-- 信息发送板块  -->
      <div class="put">
        <form action="http://localhost:9200/test/talk" method="post" οnsubmit="return false">
          <div class="talk_input">
            <div class="fileinput-button">
              <span class="fileinput-btn">上传附件</span>
              <input type="file" id="importFile" />
            </div>
            <input type="text" class="talk_word" id="talkwords">
            <!-- <input type="button" value="发送" class="talk_sub" id="talksub"> -->
            <input type="submit" value="发送" />
          </div>
        </form>
      </div>
      <!-- <iframe id="iframeForm" name="iframeForm" style="display:none;"></iframe> -->

    </div>
	
  </div>

</template>

<script>
/* import {Rite} from "../views/Rite.vue"; */
  export default {
    created() {
		// $.get("http://localhost:9200/test/talk", { username:'吕博'});
		// let _this=this;
      window.onload = function () {

        var Words = document.getElementById("words");
        var Who = document.getElementById("who");
        var TalkWords = document.getElementById("talkwords");
        var TalkSub = document.getElementById("talksub");
		let aa='dd'
        $().ready(function () {
          setInterval(function () {

            $.ajax({

              type: "get",

              url: "http://localhost:9200/test/talk?username="+aa,

              contentType: "application/json;charset=utf-8",

              async: true, //设置是否异步，默认为异步

              dataType: "json",
			  
// params:{
// 	aa:'ss'
// }
              success: function (data) { //返回的结果
                var talktext = data.talktext //发送方消息文本
                var listentext = data.listentext //接收方消息文本
                var talkImg = data.talkImg //发送方用户头像
                var listenImg = data.listenImg //接收方用户头像
                var talktextImg = data.talktextImg //发送方文本中的图片
                var listentextImg = data.listentextImg //接收方文本中的图片
                var msg = data.msg //0表示有新消息，1表示没有新消息
                var userId = data.userId //用户id，用来表示是发送者还是接收者
                if (msg !== 0) {
                  if (userId == "left") {

                    str =
                      '<img src=' + listenImg + ' width="20" height="23"/><div class="atalk"><span>' +
                      listentext + '<img src=' + listentextImg + ' />' + '</span></div>';
                    document.getElementById("words").append('<div id="asay">' +
                      str + '</div>')
                  }
                  if (userId == "right") {

                    str =
                      '<div class="bimg"><img src=' + talkImg + ' width="20" height="23"/></div>' +
                      '<div class="bout"><div class="btalk" >' + talktext + '<img src=' + talktextImg +
                      ' />' +
                      '</div></div>';
                    document.getElementById("words").append('<div id="asay">' +
                      str + '</div>')
                  }
				  // _this.aa();
                }

              },

              error: function (data) {

                alert("提交失败" + JSON.stringify(data));

              }

            });
          }, 2000)
        });

      }
    },
    methods:{
		// aa(){
			
		// }

    }
  }
</script>

<style>
  .talk_con {
    width: 280px;
    height: 350px;
    border: 5px solid #ffffff;
    margin: 50px auto 0;
    background: #ffffff;
  }

  .talk_show {
    width: 280px;
    height: 345px;
    border: 3px solid #98fff3;
    background: #fffcc9;
    margin: 10px auto 0;
    overflow: auto;
  }

  .talk_input {
    width: 300px;
    margin: 10px auto 0;
    overflow: auto;
  }

  .whotalk {
    width: 80px;
    height: 30px;
    float: left;
    outline: none;
  }

  .talk_word {
    width: 160px;
    height: 35px;
    padding: 0px;
    float: left;
    margin-left: 10px;
    outline: none;
    text-indent: 10px;
  }

  .put {
    width: 280px;
    border: 2px solid #98fff3;
    background: #fffcc9;
  }

  .talk_sub {
    width: 56px;
    height: 30px;
    float: left;
    margin-left: 10px;
  }

  .atalk {
    margin: 10px;
    width: 220px;
  }

  .atalk span {
    display: inline-block;
    background: #0181cc;
    border-radius: 10px;
    color: #fff;
    padding: 5px 10px;
    display: table-cell
  }

  .btalk {
    margin: 10px;
    text-align: left;
    display: inline-block;
    background: #ef8201;
    border-radius: 10px;
    color: #fff;
    padding: 5px 10px;
    max-width: 150px;
    display: inline-block;
  }

  .bout {
    text-align: right;
    width: 100%;
  }

  .bimg {
    float: right
  }

  .fileinput-button {
    position: relative;
    display: inline-block;
  }

  .fileinput-button .fileinput-btn {
    display: inline-block;
    width: 60px;
    height: 33px;
    background: #FFFFFF;
    border-radius: 18px;
    border: 1px solid #5CDAA8;
    color: #5CDAA8;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
  }

  .fileinput-button input {
    position: absolute;
    right: 0;
    top: 0;
    left: 0;
    outline: none;
    opacity: 0;
    display: inline-block;
    width: 60px;
    height: 36px;
  }
  /* 杨帅 评价模板*/
   
</style>